/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CrearCompra.java
 *
 * Created on 14/09/2012, 09:33:36 PM
 */

package frontera;


import Entidad.Compra;
import java.util.ArrayList;
import java.util.Calendar;
/**
 *
 * @author Andres
 */
public class CrearCompra extends javax.swing.JFrame {

    /** Creates new form CrearCompra */
    public CrearCompra() {
        super("Nueva Compra");
        initComponents();
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        LProducto = new javax.swing.JLabel();
        TProducto = new javax.swing.JTextField();
        LIdProducto = new javax.swing.JLabel();
        LCliente = new javax.swing.JLabel();
        LFecha = new javax.swing.JLabel();
        TIdProducto1 = new javax.swing.JTextField();
        TCliente = new javax.swing.JTextField();
        TDia = new javax.swing.JTextField();
        LDia = new javax.swing.JLabel();
        LMes = new javax.swing.JLabel();
        LYear = new javax.swing.JLabel();
        TMes = new javax.swing.JTextField();
        TYear = new javax.swing.JTextField();
        Guardar = new javax.swing.JButton();
        TIdProducto2 = new javax.swing.JTextField();
        TIdProducto3 = new javax.swing.JTextField();
        TIdProducto4 = new javax.swing.JTextField();
        TIdProducto5 = new javax.swing.JTextField();
        LValor = new javax.swing.JLabel();
        TValor = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        LProducto.setText("Producto :");

        LIdProducto.setText("Clave Productos :");

        LCliente.setText("Cliente :");

        LFecha.setText("Fecha :");

        TIdProducto1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TIdProducto1ActionPerformed(evt);
            }
        });

        LDia.setText("Dia :");

        LMes.setText("Mes :");

        LYear.setText("Año :");

        Guardar.setText("Guardar");
        Guardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                GuardarActionPerformed(evt);
            }
        });

        TIdProducto4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TIdProducto4ActionPerformed(evt);
            }
        });

        TIdProducto5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TIdProducto5ActionPerformed(evt);
            }
        });

        LValor.setText("Valor Total :");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(458, Short.MAX_VALUE)
                .addComponent(Guardar)
                .addGap(57, 57, 57))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(43, 43, 43)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(LValor)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(TValor, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(LProducto)
                                    .addComponent(LCliente))
                                .addGap(36, 36, 36)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(TProducto, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(57, 57, 57)
                                        .addComponent(LIdProducto))
                                    .addComponent(TCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(LFecha)
                                .addGap(36, 36, 36)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                        .addComponent(TDia, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(TMes, 0, 0, Short.MAX_VALUE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                        .addComponent(LDia)
                                        .addGap(26, 26, 26)
                                        .addComponent(LMes)))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(TYear, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(LYear))))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(TIdProducto3, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE)
                            .addComponent(TIdProducto2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE)
                            .addComponent(TIdProducto1, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE)
                            .addComponent(TIdProducto4, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE)
                            .addComponent(TIdProducto5, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE))
                        .addGap(93, 93, 93))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(41, 41, 41)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, false)
                    .addComponent(LProducto)
                    .addComponent(TProducto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(LIdProducto)
                    .addComponent(TIdProducto1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(TIdProducto2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(8, 8, 8)
                        .addComponent(TIdProducto3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(TCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(LCliente))))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(TIdProducto4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(TIdProducto5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(156, 156, 156)
                        .addComponent(Guardar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(26, 26, 26))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(LFecha)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(LDia)
                                    .addComponent(LMes)
                                    .addComponent(LYear))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, false)
                                    .addComponent(TDia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(TMes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(TYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(50, 50, 50)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(LValor)
                            .addComponent(TValor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(127, 127, 127))))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 372, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void TIdProducto1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TIdProducto1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_TIdProducto1ActionPerformed

    private void GuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GuardarActionPerformed

        try{
        Compra a = new Compra();

        Calendar b= null;
        b.set(Integer.parseInt(TYear.getText()),Integer.parseInt(TMes.getText()),
                Integer.parseInt(TDia.getText()));

        ArrayList c = new ArrayList();
        if(TIdProducto1.getText() != ""){c.add(TIdProducto1.getText());}
        if(TIdProducto2.getText() != ""){c.add(TIdProducto2.getText());}
        if(TIdProducto3.getText() != ""){c.add(TIdProducto3.getText());}
        if(TIdProducto4.getText() != ""){c.add(TIdProducto4.getText());}
        if(TIdProducto5.getText() != ""){c.add(TIdProducto5.getText());}

        //a.setFecha(b);
        a.setID(Integer.parseInt(TIdProducto1.getText()));
        a.setValor(Integer.parseInt(TValor.getText()));
        a.getCliente().setID(Double.parseDouble(TCliente.getText()));
        a.setProducto(c);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }//GEN-LAST:event_GuardarActionPerformed

    private void TIdProducto4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TIdProducto4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_TIdProducto4ActionPerformed

    private void TIdProducto5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TIdProducto5ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_TIdProducto5ActionPerformed

    /**
    * @param args the command line arguments
    */
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Guardar;
    private javax.swing.JLabel LCliente;
    private javax.swing.JLabel LDia;
    private javax.swing.JLabel LFecha;
    private javax.swing.JLabel LIdProducto;
    private javax.swing.JLabel LMes;
    private javax.swing.JLabel LProducto;
    private javax.swing.JLabel LValor;
    private javax.swing.JLabel LYear;
    private javax.swing.JTextField TCliente;
    private javax.swing.JTextField TDia;
    private javax.swing.JTextField TIdProducto1;
    private javax.swing.JTextField TIdProducto2;
    private javax.swing.JTextField TIdProducto3;
    private javax.swing.JTextField TIdProducto4;
    private javax.swing.JTextField TIdProducto5;
    private javax.swing.JTextField TMes;
    private javax.swing.JTextField TProducto;
    private javax.swing.JTextField TValor;
    private javax.swing.JTextField TYear;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables

}
